package org.edu.modules.research.rproject.service.impl;

import org.apache.shiro.SecurityUtils;
import org.edu.common.base.BasePageDto;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.system.vo.LoginUser;
import org.edu.common.utils.ConvertUtils;
import org.edu.common.base.BaseServiceImpl;
import org.edu.modules.research.rbase.service.VeJkyFileService;
import org.edu.modules.research.rproject.mapper.VeJkyProjectPlanMapper;
import org.edu.modules.research.rproject.entity.VeJkyProjectPlan;
import org.edu.modules.research.rproject.dto.VeJkyProjectPlanDto;
import org.edu.modules.research.rproject.service.VeJkyProjectPlanService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


/**
 * 实现类
 */
@Service
public class VeJkyProjectPlanServiceImpl extends BaseServiceImpl<VeJkyProjectPlan, VeJkyProjectPlanMapper> implements VeJkyProjectPlanService {

    @Autowired
    private VeJkyFileService veJkyFileService;

    public IPage<VeJkyProjectPlanDto> pageDto(BasePageDto page, @Param(Constants.WRAPPER) Wrapper queryWrapper){
        return mapper.pageDto(page,queryWrapper);
    }
    /**
    * 查询实体类
    */
    public VeJkyProjectPlanDto findDtoById(String id) {
        VeJkyProjectPlan entity = super.findById(id);
        VeJkyProjectPlanDto dto = ConvertUtils.convertToDto(entity, VeJkyProjectPlanDto.class);
        return dto;
    }

    /**
    * 新增或者修改
    */
    public void insertOrUpdate(VeJkyProjectPlanDto dto,Boolean isAdd){
        Date now = new Date();
        if(isAdd){
            LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
            dto.setCreateUid(sysUser.getId());
            dto.setCreateName(sysUser.getRealname());
            dto.setCreateTime(now);
            super.insert(dto);
        }else{
            super.update(dto);
        }
        veJkyFileService.updateFiles(dto.getFileIds(),dto.getId()+"","projectPlan");
    }

}
